package cn.ctodb.im.server;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cn.ctodb.im.core.PacketReceiver;
import cn.ctodb.im.dto.Command;
import cn.ctodb.im.handler.HeartBeatHandler;
import cn.ctodb.im.utils.MsgPackDecode;
import cn.ctodb.im.utils.MsgPackEncode;

@Configuration
public class ServerConfiguration {

	@Autowired
	private ServerProperties serverProperties;

	@Bean
	public ServerHandler serverHandler() {
		return new ServerHandler(packetReceiver());
	}

	@Bean
	public MsgPackEncode msgPackEncode() {
		return new MsgPackEncode();
	}

	@Bean
	public MsgPackDecode msgPackDecode() {
		return new MsgPackDecode();
	}

	@Bean
	public PacketReceiver packetReceiver() {
		PacketReceiver packetReceiver = new PacketReceiver();
		packetReceiver.register(Command.HEARTBEAT, heartBeatHandler());
		return packetReceiver;
	}

	@Bean
	public HeartBeatHandler heartBeatHandler() {
		return new HeartBeatHandler();
	}
}
